package com.capgemini.scaffold.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.capgemini.scaffold.common.ResponseBean;

import com.capgemini.scaffold.common.valid.AddGroup;
import com.capgemini.scaffold.common.valid.UpdateGroup;
import com.capgemini.scaffold.dto.InternDTO;
import com.capgemini.scaffold.dto.TutorDTO;
import com.capgemini.scaffold.entity.Intern;
import com.capgemini.scaffold.entity.Tutor;
import com.capgemini.scaffold.service.TutorService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * 导师controller类
 */
@Api("导师")
@RestController
@RequestMapping("/tutor")
public class TutorController {
    @Autowired
    private TutorService tutorService;


    @ApiOperation("页面直接展示导师信息")
    @GetMapping
    public ResponseBean<List<Intern>> queryTutor()  {
        return tutorService.queryTutor();
    }


    @ApiOperation("新增导师")
    @PostMapping("/add")
    public ResponseBean<Tutor> addNewTutor(@Validated(AddGroup.class) @RequestBody @Valid Tutor tutor) {
        return ResponseBean.success(tutorService.addNewTutor(tutor));
    }

    @ApiOperation("修改导师信息")
    @PutMapping("/update")
    public ResponseBean<Integer> updateTutor(@Validated(UpdateGroup.class) @RequestBody Tutor tutor) {
        return ResponseBean.success(tutorService.updateTutor(tutor));
    }

    @ApiOperation("根据id获取导师信息")
    @GetMapping("/get/{id}")
    public ResponseBean<Tutor> selectById(@PathVariable("id") Integer id) {
        return ResponseBean.success(tutorService.selectById(id));
    }

    @ApiOperation("点击导师姓名查询学员姓名分页信息")
    @PostMapping("/queryTutorInternPage/{id}")
    public ResponseBean<IPage<Intern>> queryTutorInPage(@RequestBody InternDTO req , @PathVariable("id") Integer id) {
        return ResponseBean.success(tutorService.queryInternPage(req,id));
    }

    @ApiOperation("分页查询导师信息")
    @PostMapping("/queryTutorPage")
    public ResponseBean<IPage<Tutor>> queryTutorPage(@RequestBody TutorDTO req) {
        return ResponseBean.success(tutorService.queryTutor(req));
    }

    @ApiOperation("导师模糊查询接口")
    @PostMapping("/queryTutor")
    public ResponseBean<List<Intern>> queryTutor(@RequestBody TutorDTO req) {
        return ResponseBean.success(tutorService.linkTutor(req));
    }

    @ApiOperation("根据id删除导师")
    @DeleteMapping("/delete/{id}")
    public ResponseBean deleteById(@PathVariable("id") Integer id) {
        return ResponseBean.success(tutorService.deleteTutorId(id));
    }

    @ApiOperation("导师待教学员模糊查询接口")
    @PostMapping("/tutorByIntern/{id}")
    public ResponseBean<List<Intern>> queryTutor(@RequestBody InternDTO req,@PathVariable("id") Integer id) {
        return ResponseBean.success(tutorService.linkIntern(req,id));
    }
}
